package router

import (
	"github.com/gin-gonic/gin"
	"hosptial-record/api/user"
	"hosptial-record/middlewares"
)

func InitUserRouter(group *gin.RouterGroup) {
	router := group.Group("user")
	{
		router.POST("login", user.Login)
		router.Use(middlewares.JWTAuth()).PATCH("changePwd", user.ChangePassword)
		router.GET("ownInfo", middlewares.JWTAuth(), user.OwnDetail)
		router.Use(middlewares.JWTAuth(), middlewares.IsAdminAuth()).GET("", user.List)
		router.Use(middlewares.JWTAuth(), middlewares.IsAdminAuth()).GET(":id", user.Detail)
		router.Use(middlewares.JWTAuth(), middlewares.IsAdminAuth()).DELETE(":id", user.Delete)
		router.Use(middlewares.JWTAuth(), middlewares.IsAdminAuth()).POST("", user.Create)
		router.Use(middlewares.JWTAuth(), middlewares.IsAdminAuth()).PATCH("", user.Update)
		router.Use(middlewares.JWTAuth(), middlewares.IsAdminAuth()).PATCH("disable", user.Disable)
	}

	admin := router.Group("admin")
	admin.Use(middlewares.JWTAuth(), middlewares.IsAdminAuth())
	{
		admin.PATCH("", user.AdminUpdate)
	}
}
